package atom;

import java.util.concurrent.CountDownLatch;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-10-24
 * Time: 20:50
 */

public class Demo5 {
    public static void main(String[] args) throws InterruptedException {
        //表示有几个选手参赛
        CountDownLatch countDownLatch = new CountDownLatch(10);

        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(() -> {
                try {
                    Thread.sleep(3000);
                    System.out.println(Thread.currentThread().getName() + "跑完了 到达终点了");
                    countDownLatch.countDown();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            t.start();
        }
        //裁判就要等待所有的线程到达 当线程没有执行完就阻塞
        countDownLatch.await();
    }
}
